<template>

</template>

<script>
    import _ from 'lodash'
    import * as u from '@/util/util'
    export default {
        components: {
            'componentBox': () => import('@/components/screen/componentBox.vue'),
            'my_chart': () => import('@/components/myChart/index.vue'),
        },
        props: {
            id: String,
            config: Object,
        },
        watch:{
            "config.data":{
                handler(newVal){
                    this.data=newVal;
                    this.key++;
                },
                deep:true,
            },
            "config.option.echartOption":{
                handler(newVal){
                    this.key++;
                },
                deep:true,
            },
        },
        data() {
            return {
                data: [],
                key: 1,

            }
        },
        created() {
            if(this.config.data.length>0 && this.config.data!=null){
                this.data=u.copyBean(this.config.data);
            }
        },
        computed:{
            // 图表配置项
            option () {
                const that = this
                // 通过获取传入对象的属性的个数，生成serieArr
                let serieNum = Object.keys(that.data[0]).length - 1
                let serieArr = []
                for (let i = 0; i < serieNum; i++) {
                    serieArr.push({
                        type: 'bar',
                    })
                }
                // 返回默认配置项与传入配置合并后的option，生成图表
                return _.merge({
                    dataset: {
                        source: that.data
                    },
                    series: serieArr
                }, that.config.option.echartOption);
            }
        }
    }
</script>

<style scoped>

</style>
